package com.mapbar.ure;

import java.util.ArrayList;

/**
 * 这里的代码目前还很混乱，通用型不足。
 * 
 * @author qin
 * 
 */
public enum ProductionType {
	Goal, RE, T, A, F, AvailableCharSet, Or, Wildcard, Cons, Closure, OpeningParenthesis, ClosingParenthesis, EOF, List, Pair;

	static public boolean isNonterminal(ProductionType t) {
		return (t != OpeningParenthesis && t != ClosingParenthesis && t != Or
				&& t != Cons && t != Closure && t != AvailableCharSet);
	}

	static public boolean isAvailableCharSet(ProductionType t) {
		return (t == AvailableCharSet);
	}

	static public boolean isTerminal(ProductionType t) {
		return !isNonterminal(t);
	}

	public static boolean isNotGoal(ProductionType left) {
		return left != Goal;
	}

	public static boolean isGoal(ProductionType left) {
		return !isNotGoal(left);
	}

	public static boolean isEOF(ProductionType terminalSymbol) {
		return terminalSymbol == EOF;
	}

	public static ProductionType[] nonTerminalSet() {
		java.util.List<ProductionType> ret = new ArrayList<ProductionType>();
		for (ProductionType t : ProductionType.values()) {
			if (ProductionType.isNonterminal(t)) {
				ret.add(t);
			}
		}
		return ret.toArray(new ProductionType[ret.size()]);
	}
}
